package com.markhsiu.nio.proxy;

public class ProxyServer {

	
	public static void main(String[] args) {
		 ProxyServer server = new ProxyServer();
		 try {
			server.init();
			server.start();
		} catch (Exception e) {
			e.printStackTrace();
			server.stop();
		}
	}
	
	private String[] local_ip = new String[]{"127.0.0.1","127.0.0.1"};
	private String[] remote_ip = new String[]{"127.0.0.1","127.0.0.1"};
	private int[] local_port = new int[]{1001,1002};
	private int[] remote_port = new int[]{30010,80};
	
	private ProxyAcceptorTask[] tasks;
	public void init(){
		int size = local_ip.length;
		tasks = new ProxyAcceptorTask[size];
		for(int i=0;i<size;i++){
			ProxyBean bean = new ProxyBean();
			bean.local_ip = local_ip[i];
			bean.local_port = local_port[i];
			bean.remote_ip = remote_ip[i];
			bean.remote_port = remote_port[i];
			
			ProxyAcceptorTask task = new ProxyAcceptorTask(bean);
			tasks[i] = task;
		}
	}
	
	public void start(){
		for(ProxyAcceptorTask task : tasks){
			task.start();
		}
	}
	
	public void stop(){
		for(ProxyAcceptorTask task : tasks){
			task.close();
		}
	}
}
